package com.handinfo.uimenu.window;

import javax.microedition.io.ConnectionNotFoundException;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

import android.widget.Toast;

import com.handinfo.engine.AbstractGameScreen;
import com.handinfo.engine.GameMIDlet;
import com.handinfo.engine.GameManager;
import com.handinfo.game.ActorRole;
import com.handinfo.game.UserScreen;
import com.handinfo.uimenu.UIAbstractWindow;
import com.handinfo.uimenu.UIListener;
import com.handinfo.uimenu.UIManager;
import com.handinfo.uimenu.UIMessageBox;
import com.handinfo.uimenu.UIPopmenu;
import com.handinfo.uimenu.UITools;
import com.handinfo.uimenu.UIWindowFactory;
import com.handinfo.util.Tools;
import com.test.touch.GameTouchManager;
import com.xl.lib.Utils;

public class UIMenu extends UIAbstractWindow
{
	private final int STATE_MENU_LEFT = 1;
	private final int STATE_MENU_RIGHT = 2;
	private final int STATE_MENU_EQUIP = 3;//
	private final int STATE_MENU_SET_SHORTCUT = 4;// 选中某一个菜单
	private final int STATE_MENU_LEARN_SKILL = 5;// 选中某一个菜单
	private final int STATE_MENU_TASK = 6;// 打开任务
	//
	private int m_index;// 当前选择
	private final int NUM_ROW = 3;
	private final int NUM_COL = 3;
	//
	private final String TITLE = "系统";
	private final int IW = 5;
	private final int IH = 5;
	private final int W_LABEL = UITools.W_LABEL_MIDDLE + 4;
	private final int H_LABEL = UITools.H_LABEL;

	private final int W_BG = 160;
	private final int H_BG = 150;
	private final int Y_LABEL = UIManager.IMAGE_TITlE_MIDDLE.getHeight()
			+ ((H_BG - UIManager.IMAGE_TITlE_MIDDLE.getHeight() - ((H_LABEL + IH) << 2) - IH) >> 1);
	private final int X_LABEL = ((W_BG - ((W_LABEL + IW) * 3 - IW)) >> 1);

	// private String[] m_menus;
	private Image[] m_images;
	private boolean m_isLeft;
	//
	private String[] m_yindaos;
	private int W_YINDAO = 70;

	/**********************/
	// Sel
	/**********************/

	public UIMenu(int id)
	{
		super(id);
		if( id != UIWindowFactory.WINDOW_MENU_LR){
			setBounds(0, 0, W_BG, H_BG);
			setCentre();
		}
	}


	protected void onTouchRect(int[][] rect, int touchid) {
		super.onTouchRect(rect, touchid);
		if (exit_progress>0) {
		    return;
		}
		if (rect == leftMenu || rect == rightMenu) {
			int size = rect.length;
			if (touchid == size-1) {
				GameTouchManager.keyPressedRSoft();
			} else {
				if (m_index == touchid) {
					GameTouchManager.keyPressedFire();
				} else {
					m_index = touchid;
				}
			}
		}
	}


	protected void registerTouch() {
//		super.registerTouch();

		switch(m_state) {
		case STATE_MENU_LEFT:
			initTouchRect(leftMenu);
			break;
		case STATE_MENU_RIGHT:
			initTouchRect(rightMenu);
			break;
		}
	}

	int[][] leftMenu = new int[][]{
			{178,115,38,22},
			{221,115,38,22},
			{264,115,38,22},

			{178,142,38,22},
			{221,142,38,22},
			{264,142,38,22},

			{178,169,38,22},
			{221,169,38,22},
			{264,169,38,22},

			{199,196,82,22},
//			{0,0,480,320},
			{160,85,158,149,-1},
//			{0,0,480,320},
	};

	int[][] rightMenu = new int[][]{
			{178,101,38,22},
			{221,101,38,22},
			{264,101,38,22},

			{178,128,38,22},
			{221,128,38,22},
			{264,128,38,22},

			{178,155,38,22},
			{221,155,38,22},
			{264,155,38,22},

			{199,182,82,22},
			{199,209,82,22},
			{160,70,158,178,-1},
//			{0,0,480,320},
	};



	public void setBoundLR(boolean isLeft){
		if( isLeft){
			setBounds(0, 0, W_BG, H_BG);
		}else{
			setBounds(0, 0, W_BG, H_BG + H_LABEL + IH);
		}
		setCentre();
	}
	public static final void openMenu(boolean isLeft)
	{
		// UIMenu.openMenuInEquip();
		openMenu(isLeft, 4);// 普通状态下进入系统菜单
	}

	private static final void openMenu(boolean isLeft, int defaultIndx)
	{
		UIMenu menu = (UIMenu) UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_MENU_LR);
		menu.m_isLeft = isLeft;
		menu.m_index = defaultIndx;
		if (isLeft) {
			menu.changeState(menu.STATE_MENU_LEFT);
		}
		else {
			menu.changeState(menu.STATE_MENU_RIGHT);
		}
		menu.setBoundLR(isLeft);
	}

	public static final void gotoTeachEquip()
	{
		UIMenu menu = (UIMenu) UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_MENU_LR);
		menu.m_isLeft = false;
		menu.m_index = 4;
		menu.changeState(menu.STATE_MENU_EQUIP);

		menu.m_yindaos = Tools.getStrArray("单击打开背包", menu.W_YINDAO);
	}

	public static final void gotoTeachLearnSkill()
	{
		UIMenu menu = (UIMenu) UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_MENU_LR);
		menu.m_isLeft = false;
		menu.m_index = 2;
		menu.changeState(menu.STATE_MENU_LEARN_SKILL);

		menu.m_yindaos = Tools.getStrArray("单击打开技能", menu.W_YINDAO);
	}

	public static final void gotoTeachSetShortcut()
	{
		UIMenu menu = (UIMenu) UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_MENU_LR);
		menu.m_isLeft = false;
		menu.m_index = 7;
		menu.changeState(menu.STATE_MENU_SET_SHORTCUT);
		menu.m_yindaos = Tools.getStrArray("单击打开设置快捷栏菜单", menu.W_YINDAO);
	}

	/**
	 * 2012-4-17 下午05:36:59
	 * venizeng
	 */
	public static void gotoTeachTask()
	{
		UIMenu menu = (UIMenu) UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_MENU_LR);
		menu.m_isLeft = false;
		menu.m_index = 3;
		menu.changeState(menu.STATE_MENU_TASK);
		menu.m_yindaos = Tools.getStrArray("单击打开任务", menu.W_YINDAO);
	}

	private void changeState(int state)
	{
		m_state = state;
		//
		if (m_isLeft) {
			m_images = new Image[] { UIManager.IMAGE_MENU_HUODONG, UIManager.IMAGE_MENU_DUIWU,
					UIManager.IMAGE_MENU_SHEHUI, UIManager.IMAGE_MENU_JIAZU, UIManager.IMAGE_MENU_PAIHANG,
					UIManager.IMAGE_MENU_LIAOTIAN
					, UIManager.IMAGE_MENU_YOUJIAN, UIManager.IMAGE_MENU_PAIMAI, UIManager.IMAGE_MENU_FUWU,
					UIManager.IMAGE_MENU_QIEHUANJUESE };
		}
		else {
			m_images = new Image[] { UIManager.IMAGE_MENU_SHANGCHENG, UIManager.IMAGE_MENU_SHUXING,
					UIManager.IMAGE_MENU_JINENG, UIManager.IMAGE_MENU_RENWU
					, UIManager.IMAGE_MENU_BEIBAO, UIManager.IMAGE_MENU_DONGFU, UIManager.IMAGE_MENU_DITU,
					UIManager.IMAGE_MENU_SHEZHI, UIManager.IMAGE_GONGLUE, UIManager.IMAGE_MENU_ZIDONGDAGUA,UIManager.IMAGE_MENU_TUICHUYOUXI };
		}
		if (m_state == STATE_MENU_LEFT || m_state == STATE_MENU_RIGHT) {
			m_yindaos = null;
		}

		registerTouch();
	}

	protected void keyLogic()
	{
		switch (m_state) {
			case STATE_MENU_EQUIP:
				if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
						|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
					setWindowStatus(STATE_MENU_RIGHT);
					m_yindaos = null;
					UIBag.gotoTeachEquip();
				}
				break;
			case STATE_MENU_LEARN_SKILL:
				if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
						|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
					setWindowStatus(STATE_MENU_RIGHT);
					m_yindaos = null;
					UISkill.gotoTeachLearnSkill();
				}
				break;
			case STATE_MENU_SET_SHORTCUT:
				if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
						|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
					setWindowStatus(STATE_MENU_RIGHT);
					m_yindaos = null;
					UISetShortCut.gotoTeachSetMenu();
				}
				break;
			case STATE_MENU_TASK:
				if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
						|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
					setWindowStatus(STATE_MENU_RIGHT);
					m_yindaos = null;
					UITaskWindow.gotoTeach();
				}
				break;
			default:
				keyLogicOnNormal();
				break;
		}
	}

	private void keyLogicOnNormal()
	{
		if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
            if (exit_progress == 0) {//日本人
                close();
              } else {
                  if (exit_progress == 1) {
                      exit_progress = 0;
                      registerTouch();
                  } else if (exit_progress == 2) {
                      System.exit(1);
                  }
              }
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_UP)) {
			if (m_index == m_images.length - 1) {
				if( m_isLeft ){
					m_index -= 2;
				}else{
					m_index --;
				}
				return;
			}
			if (m_index < NUM_COL) {
				m_index = m_images.length - 1;
			}
			else {
				m_index -= NUM_COL;
			}
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_DOWN)) {
			if (m_index == m_images.length - 1) {
				if( m_isLeft ){
					m_index -= (NUM_ROW * NUM_COL);
				}else{
					m_index -= (NUM_ROW * NUM_COL)+1;
				}

			}
			else {
				if (m_index > (NUM_COL + (NUM_ROW - 1))) {
					if( m_isLeft ){
						m_index = m_images.length - 1;
					}else{
						if(m_index != m_images.length - 2){
							m_index = m_images.length - 2;
						}else{
							m_index = m_images.length - 1;
						}
					}
				}
				else {
					m_index += NUM_COL;
				}
			}
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT)) {
			if (m_index == 0) {
				m_index = m_images.length - 1;
			}
			else {
				m_index--;
			}
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT)) {
			if (m_index == m_images.length - 1) {
				m_index = 0;
			}
			else {
				m_index++;
			}
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
				|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
	           if (exit_progress != 0) {
                   if (exit_progress == 1) {
                       exit_progress = 2;
                   } else if (exit_progress == 2) {
                       try {
                           GameMIDlet.s_instance.platformRequest(GameMIDlet.MORE_GAME_URL);
                       } catch (ConnectionNotFoundException e) {
                           Toast.makeText(Utils.getContext(), "联网失败，请检测网络！", Toast.LENGTH_SHORT).show();
                           e.printStackTrace();
                       }
                       Utils.getContext().finish();
                       System.exit(1);
                   }
               } else {
           click(m_index);
               }
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY1)) {
			m_index = 0;
			click(m_index);
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY2)) {
			m_index = 1;
			click(m_index);
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY3)) {
			m_index = 2;
			click(m_index);
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY4)) {
			m_index = 3;
			click(m_index);
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY5)) {
			m_index = 4;
			click(m_index);
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY6)) {
			m_index = 5;
			click(m_index);
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY7)) {
			m_index = 6;
			click(m_index);
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY8)) {
			m_index = 7;
			click(m_index);
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY9)) {
			m_index = 8;
			click(m_index);
		}
		else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY0)) {
			if(m_isLeft){
				m_index = 9;
			}else{
				m_index = 10;
			}
			click(m_index);
		}
	}

	private void click(int index)
	{
		if (m_isLeft) {
			clickLeft(index);
		}
		else {
			clickRight(index);
		}
	}

	private void clickLeft(int index)
	{
		switch (index) {
			case 0:// STR_MENU_HUODONG
				if (GameManager.getInstance().m_role.isAliveStatus()) {
					eventOpen();
				}
				break;
			case 1:// STR_MENU_DUIWU
				if (GameManager.getInstance().m_role.isAliveStatus()) {
					GameManager.getInstance().m_game_message.sendTeamAllMsg();
					UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_ID_TEAM);
				}
				break;
			case 2:// STR_MENU_SHEJIAO
				if (GameManager.getInstance().m_role.isAliveStatus()) {
					UISocialWindow.openSocialList();
				}
				break;
			case 3:// STR_MENU_JIAZU
				if (GameManager.getInstance().m_role.isAliveStatus()) {
					GameManager.getInstance().m_game_message.sendFamilyOwnMessage();
				}
				break;
			case 4:// STR_MENU_PAIHANG
				theChartsOpen();
				break;
			case 5:// STR_MENU_LIAOTIAN
				UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_CHAT);
				break;
			case 6:// STR_MENU_YOUJIAN
				if (GameManager.getInstance().m_role.isAliveStatus()) {
					UIMailList.openMailMenu();
				}
				break;
			case 7:// STR_MENU_PAIMAI
				if (GameManager.getInstance().m_role.isAliveStatus()) {
					UIAuction.openMenu();
				}
				break;
			case 8:// STR_MENU_YULIU
				if (GameManager.getInstance().m_role.isAliveStatus()) {
					clickYuliu();
				}
				break;
			case 9:// STR_MENU_RESEL
				resel();
				break;
		}
	}

	private void eventOpen()
	{
		final UIPopmenu pop1 = (UIPopmenu) UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_POPMENU);
		pop1.setPopmenus(new String[] { "1.每日任务", "2.副本", "3.系统公告" });
		pop1.addListener(new UIListener() {
			public void actionPerformed()
			{
				if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
						|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
					int index = pop1.getCurrentIndex();
					if (index == 0) {
						GameManager.getInstance().m_game_message.sendOpenActivity();
						UIManager.getInstance().removeWindow(pop1);
					}
					else if (index == 1) {
						GameManager.getInstance().m_game_message.sendGameCarbonOpen();
						UIManager.getInstance().removeWindow(pop1);
					}
					else if (index == 2) {
//						GameManager.getInstance().m_game_message.sendOpenFBActivity();
//						UIManager.getInstance().removeWindow(pop1);
						GameManager.getInstance().m_game_message.sendAnnouncement();
						UIManager.getInstance().removeWindow(pop1);
						//GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_A, "暂未开启,敬请期待!");
					}
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
					UIManager.getInstance().removeWindow(pop1);
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY1)) {
					GameManager.getInstance().m_game_message.sendOpenActivity();
					UIManager.getInstance().removeWindow(pop1);
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY2)) {
					GameManager.getInstance().m_game_message.sendGameCarbonOpen();
					UIManager.getInstance().removeWindow(pop1);
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY3)) {
					GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_A, "暂未开启,敬请期待!");
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY4)) {
					GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_A, "暂未开启,敬请期待!");
				}
			}
		});
	}

	private void theChartsOpen()
	{
		final UIPopmenu pop = (UIPopmenu) UIManager.getInstance().createWindow(
				UIWindowFactory.WINDOW_POPMENU);
		pop.setPopmenus(new String[] {
				"1.家族排名", "2.等级排名", "3.财富排名",
				"4.击杀排名", "5.贡献排名", "6.战功排名",
				"7.采集排名", "8.攻伐排名", "9.社交排名" });
		pop.addListener(new UIListener() {
			public void actionPerformed()
			{
				if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
						|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
					int index = pop.getCurrentIndex();
					if (index >= 0 && index <= 8) {
						GameManager.getInstance().m_game_message.sendRankingList((byte) (index + 1), (short) 0,
								(short) UIRankingLists.LIST_NUMBER);
						UIManager.getInstance().removeWindow(pop);
					}
					else {
						GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_A, "暂未开启,敬请期待!");
					}
					UIManager.getInstance().removeWindow(pop);
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
					UIManager.getInstance().removeWindow(pop);
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY1)) {
					GameManager.getInstance().m_game_message.sendRankingList((byte) 1, (short) 0,
							(short) UIRankingLists.LIST_NUMBER);
					UIManager.getInstance().removeWindow(pop);
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY2)) {
					GameManager.getInstance().m_game_message.sendRankingList((byte) 2, (short) 0,
							(short) UIRankingLists.LIST_NUMBER);
					UIManager.getInstance().removeWindow(pop);
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY3)) {
					GameManager.getInstance().m_game_message.sendRankingList((byte) 3, (short) 0,
							(short) UIRankingLists.LIST_NUMBER);
					UIManager.getInstance().removeWindow(pop);
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY4)) {
					GameManager.getInstance().m_game_message.sendRankingList((byte) 4, (short) 0,
							(short) UIRankingLists.LIST_NUMBER);
					UIManager.getInstance().removeWindow(pop);
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY5)) {
					GameManager.getInstance().m_game_message.sendRankingList((byte) 5, (short) 0,
							(short) UIRankingLists.LIST_NUMBER);
					UIManager.getInstance().removeWindow(pop);
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY6)) {
					GameManager.getInstance().m_game_message.sendRankingList((byte) 6, (short) 0,
							(short) UIRankingLists.LIST_NUMBER);
					UIManager.getInstance().removeWindow(pop);
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY7)) {
					GameManager.getInstance().m_game_message.sendRankingList((byte) 7, (short) 0,
							(short) UIRankingLists.LIST_NUMBER);
					UIManager.getInstance().removeWindow(pop);
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY8)) {
					GameManager.getInstance().m_game_message.sendRankingList((byte) 8, (short) 0,
							(short) UIRankingLists.LIST_NUMBER);
					UIManager.getInstance().removeWindow(pop);
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY9)) {
					GameManager.getInstance().m_game_message.sendRankingList((byte) 9, (short) 0,
							(short) UIRankingLists.LIST_NUMBER);
					UIManager.getInstance().removeWindow(pop);
				}
			}
		});
	}

	/**
	 * 预留 2012-3-27 下午02:47:14 venizeng
	 */
	private void clickYuliu()
	{
		UIManager.getInstance().removeWindow(this);
		//
		final UIPopmenu popmenu = (UIPopmenu) UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_POPMENU);
		popmenu.setPopmenus(new String[] { "脱离卡死", "联系客服", "游戏帮助" });
		popmenu.addListener(new UIListener() {

			public void actionPerformed()
							{
								if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
										|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
									switch (popmenu.getCurrentIndex()) {
										case 0:
											GameManager.getInstance().m_game_message.sendUserTuoli();
											break;
										case 1://
											UIMail.sendMailToGM();
											break;
										default:
											GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B,
													"暂不开放");
											break;
									}
									UIManager.getInstance().removeWindow(popmenu);
								}
								else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
									UIManager.getInstance().removeWindow(popmenu);
								}
							}
		});
	}

	private void clickRight(int index)
	{
		switch (index) {
			case 0:// STR_MENU_SHANGCHENG
				//谢亮添加
//				GameManager.getInstance().addMessage("暂未开放！");
				GameManager.getInstance().m_game_message.sendOpenMarket();
				break;
			case 1:// STR_MENU_SHUXING
				GameManager.getInstance().m_game_message.sendAttInfos(GameManager.getInstance().m_role.m_gameID);
				break;
			case 2:// STR_MENU_JINNENG
				if( GameManager.getInstance().m_role.m_lv < 7){
					GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, "达到6级以上才能使用此功能！");
					return;
				}
				if (GameManager.getInstance().m_role.isAliveStatus()) {
					UISkill.gotoSkill();
				}
				break;
			case 3:// STR_MENU_RENWU
				if (GameManager.getInstance().m_role.isAliveStatus()) {
					GameManager.getInstance().m_game_message.sendTaskRoleList();
				}
				break;
			case 4:// STR_MENU_BEIBAO
				if (GameManager.getInstance().m_role.isAliveStatus()) {
					UIBag.gotoNormal();
				}
				break;
			case 5:// STR_MENU_DONGFU
				if (GameManager.getInstance().m_role.isAliveStatus()) {
					GameManager.getInstance().m_game_message.sendDongFuInto(GameManager.getInstance().m_role.m_gameID);
				}
				break;
			case 6:// STR_MENU_DITU
				if (GameManager.getInstance().m_role.isAliveStatus()) {
					openWorldMap();
				}
				break;
			case 7:// STR_MENU_SHEZHI
				if (GameManager.getInstance().m_role.isAliveStatus()) {
					UISetShortCut.openSetMenu();
				}
				break;
			case 8:// STR_MENU_QICHONG
//				GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, "暂不开放");
				GameManager.getInstance().m_game_message.sendGonglue();
				break;
			case 9://STR_MENU_AUTOHANGUP
				//GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B,"暂不开放");
				if( GameManager.getInstance().m_role.m_lv < 7){
					GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, "达到6级以上才能使用此功能！");
					return;
				}
				if (GameManager.getInstance().m_role.isAliveStatus()) {
					ActorRole.m_guaji = true;
					GameManager.getInstance().m_game_message.sendAutoHangUp();
					close();
				}
				break;
			case 10:// STR_MENU_QUIT
				quit();
				break;
		}
	}

	public static void openWorldMap()
	{
		final UIPopmenu pop = (UIPopmenu) UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_POPMENU);
		pop.setPopmenus(new String[] { "1.场景信息", "2.世界地图" });
		pop.addListener(new UIListener() {
			public void actionPerformed()
			{
				if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)
						|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)) {
					int index = pop.getCurrentIndex();
					if (index == 0) {
						GameManager.getInstance().m_game_message.sendSceneMap();
					}
					else if (index == 1) {
						UINPCWindow npcwin = (UINPCWindow) UIManager.getInstance().getWindowById(
								UIWindowFactory.WINDOW_ID_NPC);
						if (npcwin == null) {
							UIManager.getInstance().addWindow(GameManager.getInstance().m_npc_window);
						}
						GameManager.getInstance().m_npc_window.initWorldMap();
						// GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_A, "暂未开启,敬请期待!");
					}
					UIManager.getInstance().removeWindow(pop);
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
					UIManager.getInstance().removeWindow(pop);
				}
			}
		});
	}

    private static int exit_progress = 0;
    private void quit()
    {
        exit_progress = 1;
        clearAllRects();
        registerNormalSoft();
//		final UIMessageBox messageBox = (UIMessageBox) UIManager.getInstance().createWindow(
//				UIWindowFactory.WINDOW_MESSAGEBOX);
//		messageBox.setMessage("是否确定退出");
//		messageBox.addListener(new UIListener() {
//
//			public void actionPerformed()
//							{
//								if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)) {
//									UIManager.getInstance().removeWindow(messageBox);
//									GameManager.getInstance().m_scene.m_isRunning = false;
//									GameManager.s_isRunning = false;
//								}
//								else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
//									UIManager.getInstance().removeWindow(messageBox);
//								}
//							}
//		});
	}

	private void resel()
	{
		final UIMessageBox messageBox = (UIMessageBox) UIManager.getInstance().createWindow(
				UIWindowFactory.WINDOW_MESSAGEBOX);
		messageBox.setMessage("是否确定重新选择");
		messageBox.addListener(new UIListener() {

			public void actionPerformed()
							{
								if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)) {
									UIManager.getInstance().removeWindow(messageBox);
									GameManager.getInstance().m_game_message.sendReSel();
									GameManager.getInstance().m_game_message.sendUserActorList();
								}
								else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
									UIManager.getInstance().removeWindow(messageBox);
								}
							}
		});
	}

	protected void paintContent(Graphics g)
	{
	    if (exit_progress > 0) {//日本人
	        UserScreen.paintExit(g, exit_progress);
            return;
        }
		paintBackGround(g);
		g.setClip(0, 0, AbstractGameScreen.SCREEN_WIDTH, AbstractGameScreen.SCREEN_HEIGHT);
		paintLabels(g, m_x + X_LABEL, m_y + Y_LABEL);
		paintYindao(g);
	}

	private int getYindaoX()
	{
		int tempX = m_x + X_LABEL;
		int W = W_LABEL + IW;
		tempX += (m_index % NUM_COL) * W;
		return tempX - IW;
	}

	private int getYindaoY()
	{
		int tempY = m_y + Y_LABEL;
		int H = H_LABEL + IH;
		tempY += (m_index / NUM_COL) * H;
		return tempY - IH;
	}

	private void paintYindao(Graphics g)
	{
		int W = W_LABEL + (IW << 1);
		int H = H_LABEL + (IH << 1);
		switch (m_state) {
			case STATE_MENU_TASK:
				UITools.paintYindao(g, m_yindaos, getYindaoX() + W, getYindaoY() + H, W_YINDAO, 2, W, H);
				break;
			default:
				UITools.paintYindao(g, m_yindaos, getYindaoX(), getYindaoY(), W_YINDAO, 4, W, H);
				break;
		}
	}

	private void paintBackGround(Graphics g)
	{
		// 绘制背景
		UITools.drawWindowBackgroud(g, m_x, m_y, m_w, m_h);
		// 绘制标题
		UITools.paintBackgroundTitleOn240320(g, m_x, m_y, m_w, m_h, TITLE);
		//
		int iw = 2;
		int ih = 2;
		UITools.paintBorderConer(g, m_x + iw, m_y + ih, m_w - (iw << 1), m_h - (ih << 1));
	}

	private void paintLabels(Graphics g, int x, int y)
	{
		int tempY = y;
		int W = W_LABEL + IW;
		int H = H_LABEL + IH;
		int num = 0;
		for (int i = 0; i < NUM_ROW; i++) {
			int tempX = x;
			for (int j = 0; j < NUM_COL; j++) {
				boolean isSel = m_index == num;
				// UITools.paintSmallLabel(g, tempX, tempY, m_menus[num], m_index == num);
				UITools.paintLabelImage(g, tempX, tempY, W_LABEL, H_LABEL, m_images[num], isSel, isSel);
				tempX += W;
				num++;
			}
			tempY += H;
		}
		//自动打怪
		if(!m_isLeft){
			paintAutoKillMonster(g, tempY);
		}
		// 退出
		paintQuit(g, tempY);
	}

	private void paintAutoKillMonster(Graphics g, int y)
	{

	    boolean isSel = m_index == 9;
		int w = UITools.W_LABEL_HUGE + 10;
		int tempX = m_x + ((m_w - w) >> 1);
		UITools.paintLabelImage(g, tempX, y, w, H_LABEL, m_images[m_images.length - 2], isSel, isSel);
	}
	private void paintQuit(Graphics g, int y)
	{
		boolean isSel;
		int tempY = y;
		if( m_isLeft ){
	       isSel = m_index == 9;
		}else{
		   isSel = m_index == 10;
		   tempY += H_LABEL + IH;
		}
		int w = UITools.W_LABEL_HUGE + 10;
		int tempX = m_x + ((m_w - w) >> 1);
		UITools.paintLabelImage(g, tempX, tempY, w, H_LABEL, m_images[m_images.length - 1], isSel, isSel);
	}

}
